package com.jsmy.softapp.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jsmy.softapp.R;
import com.jsmy.softapp.adapter.RankListAdapter;
import com.jsmy.softapp.aroute.AR;
import com.jsmy.softapp.bean.RankListBean;
import com.jsmy.softapp.net.API;
import com.jsmy.softapp.presenter.RankListPresenter;
import com.jsmy.softapp.view.RankListView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.List;

import butterknife.BindView;

@Route(path = AR.A_RANKLIST)
public class RankListActivity extends BaseActivity<RankListView, RankListPresenter> implements RankListView {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout mRefresh;
    @BindView(R.id.my_recycler)
    RecyclerView mRLv;
    RankListAdapter mAdapter;
    List<RankListBean.DataBean.ListBean> mList;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_rank_list;
    }

    @Override
    protected RankListPresenter createPresenter() {
        return new RankListPresenter();
    }

    @Override
    protected void initView() {
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RankListActivity.this.finish();
            }
        });

        mAdapter = new RankListAdapter();
        mRLv.setLayoutManager(new LinearLayoutManager(this));
        mRLv.setAdapter(mAdapter);

    }

    @Override
    protected void initData() {
        presenter.getRankList();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showLoadingData(String type, Object object) {
        switch (type) {
            case API.APP_RANK_LIST:
                mList = ((RankListBean) object).getData().getList();
                mAdapter.replaceData(mList);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        presenter.model.disposable.clear();
        super.onDestroy();
    }

}
